#ifndef XKIT_COLLECTIONS_LIST_H
#define XKIT_COLLECTIONS_LIST_H

#include "collections.h"

struct ListNode;
typedef struct ListNode ListNode;
struct ListNode {
    losu_object value;
    ListNode *front;
    ListNode *next;
};

typedef struct ListHeader {
    Reference *ref;
    ListNode *headNode;
    ListNode *tailNode;
    size_t length;
} ListHeader;

ListNode *ListNodeInit(losu_vm_t vm, Reference *ref, losu_object_t o);
void ListNodeFree(losu_vm_t vm, Reference *ref, ListNode *node);

ListHeader *ListInit(losu_vm_t vm);
void ListFree(losu_vm_t vm, ListHeader *h);
void ListAddFirst(losu_vm_t vm, ListHeader *h, losu_object_t o);
void ListAddLast(losu_vm_t vm, ListHeader *h, losu_object_t o);
void ListInsert(losu_vm_t vm, ListHeader *h, size_t index, losu_object_t o);
void ListRmFirst(losu_vm_t vm, ListHeader *h, losu_object_t target);
void ListRmLast(losu_vm_t vm, ListHeader *h, losu_object_t target);
void ListRemove(losu_vm_t vm, ListHeader *h, size_t index);
void ListGet(losu_vm_t vm, ListHeader *h, size_t index, losu_object_t target);
size_t ListSize(losu_vm_t vm, ListHeader *h);

#endif
